package com.yh.csx.crm.core.enums;

import java.util.EnumSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * PaymentTermsEnum class
 * 付款条件：01票到（货到），02月结，03预付货款
 * @author huyalin
 * @date 2019/2/23
 */
public enum PaymentTermsEnum {
    CASH7("P001", "票到7天"),
    CASH15("P002", "票到15天"),
    CASH20("P003", "票到20天"),
    CASH30("P004","票到30天"),
    MONTH_PAYMENT1("Y001","月结10天"),
    MONTH_PAYMENT2("Y002","月结15天"),
    MONTH_PAYMENT3("Y003","月结30天"),
    MONTH_PAYMENT4("Y004","月结45天"),
    MONTH_PAYMENT5("Y005","月结60天"),
    MONTH_PAYMENT6("Y006","月结90天"),
    ADVANCE("Z001","双方另议"),
    PIAODAO7("Z002","票到7天"),
    PIAODAO15("Z003","票到15天"),
    PIAODAO30("Z004","票到30天");


    private String code;
    private String name;

    PaymentTermsEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static String getName(String code) {
        for (PaymentTermsEnum paymentTermsEnum: PaymentTermsEnum.values()) {
            if (paymentTermsEnum.getCode().equals(code)) {
                return paymentTermsEnum.getName();
            }
        }
        return "";
    }

    private static final Map<String, PaymentTermsEnum> valueLookup = new ConcurrentHashMap<>(values().length);
    static {
        for (PaymentTermsEnum type : EnumSet.allOf(PaymentTermsEnum.class)) {
            valueLookup.put(type.code, type);
        }
    }

    public static PaymentTermsEnum resolve(String code) {

        return (code != null ? valueLookup.get(code) : null);
    }
    public static String resolve2(String code) {

        return (code != null ? valueLookup.get(code).name : "");
    }
}
